#include "SwitchElement.hpp"

SwitchElement::SwitchElement(float x, float y, float angle, ActionableElement* actionableElement, b2World* world) {
    this->actionableElements = new vector<ActionableElement*>();

    if (actionableElement != NULL) {
        this->addActionableElement(actionableElement);
    }

    this->numberOfContacts = 0;

    b2BodyDef bodyDefinition;
    bodyDefinition.userData = this;
    bodyDefinition.position.Set(x, y);
    bodyDefinition.angle = angle;

    b2Vec2 vertices[4];
    vertices[0].Set(-0.75f, 0.05f);
    vertices[1].Set(0.75f, 0.05f);
    vertices[2].Set(0.75f, 0.1f);
    vertices[3].Set(-0.75f, 0.1f);

    b2PolygonShape shape;
    shape.Set(vertices, 4);

    b2FixtureDef fixtureDefinition;
    fixtureDefinition.shape = &shape;
    fixtureDefinition.isSensor = true;

    this->body = world->CreateBody(&bodyDefinition);
    this->body->CreateFixture(&fixtureDefinition);
}

SwitchElement::~SwitchElement() {
    delete this->actionableElements;
}

void SwitchElement::addActionableElement(ActionableElement* actionableElement) {
    this->actionableElements->push_back(actionableElement);
}

bool SwitchElement::isSwitch() {
    return true;
}
